#include"process.h"
#include <string.h>
#include<unistd.h>

#define SIZE 101
#define STYLE '#'    //字符就应该用单引号，好久没写代码了，成傻子了









void FlushProcess(const char* sign,double total,double current)
{
  const char* sd = "|/-\\";
  int len = strlen(sd);
  char buffer[SIZE];
  static int a = 0;
  memset(buffer,0,sizeof(buffer));
  double rate = (current*100.00 / total);  //因为速度应该是百分号的
  int num = (int)rate;
  int i = 0;
  for(;i < num ; i++)
  {
      buffer[i] = STYLE;
  }
  printf("%s...[%-100s][%.1lf%%][%c]\r",sign,buffer,rate,sd[a++]);
  fflush(stdout);
  a %= len;
 // usleep(10000);
  if(num >= 100) printf("\n");
}





//v1版本的进度条，不太完美，因为有的时候下载速度不是固定的，可能是随机速递进行下载
void process()
{
  int rata = 0;
  char buffer[SIZE];
  const char* sd = "|/-\\";
  memset(buffer,0,sizeof(buffer));
  int size = strlen(sd);
  while(rata<=100)
  {
      printf("[%-100s][%d%%][%c]\r",buffer,rata,sd[rata % size]);
      fflush(stdout);
      buffer[rata++] = STYLE;
      usleep(100000);
  }
  printf("\n");

}
